#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
主题: 无穷大与NaN
问题: 你想创建或测试正无穷、负无穷或NaN(非数字)的浮点数。
提示 : 
"""

import math

def recipe1():
    a = float('inf')
    b = float('-inf')
    c = float('nan')

    print(f"{a = }")
    print(f"{b = }")
    print(f"{c = }")

    # 测试这些值的存在
    print(f"{math.isinf(a) = }")
    print(f"{math.isnan(c) = }")

    print(f"{a + 45 = }")
    print(f"{a * 45 = }")
    print(f"{10 / a = }")
    print(f"{a / a = }")        # NOSONAR
    print(f"{a + b = }")

    # NaN值会在所有操作中传播，而不会产生异常
    print(f"{c + 23 = }")
    print(f"{c / 2 = }")
    print(f"{c * 2 = }")
    print(f"{math.sqrt(c) = }")

    # NaN值的一个特别的地方时它们之间的比较操作总是返回False
    d = float('nan')
    print(f"{c == d = }")
    print(f"{c is d = }")

def main():
    print('recipe1'.center(20, '*'))
    recipe1() 

if __name__ == '__main__':
    main()       